<%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> 
 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
 <%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head> 
    <link rel="stylesheet" href="<s:url value="/resources"/>/css/common.css" type="text/css" />   
    <link rel="stylesheet" href="<s:url value="/resources"/>/css/innerstyle.css" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.custom.min.css" />
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script> 
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.form.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/json2.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.validate.min.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/messages_zh.js"></script>
<style type="text/css">
	label.error {  
	        color: red;/*错误信息的颜色*/  
	    }  
	input.error {  
	        border:1px dotted red;/*输入错误的输入框的边框样式*/  
	    }	
</style>
<script type='text/javascript'>
	$(function(){ 
	    $("#but1").button();
	    $("#but2").button(); 
	    $("#but3").button(); 
	    loadJiesdwData();
	    jiaoyan();
	    $( "#dialog-confirm" ).dialog({
            autoOpen: false,            
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
				     save();
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});  
		
		//为提交按钮绑定事件
	    $("#but1").click(function () {
             $("#dialog-confirm").dialog("open");
          });
     });
     
   //保存
	function save(){
	  if($("#form1").valid()){ 
		  var flag = true;
		  if(document.getElementById("shangjdw").value=="-1"){
	           msg ="请选择所属买受人";
	           flag =  false;
	        }
		  if (flag) {
	    var url = "<s:url value="/jydz"/>/updateMsrjsdw";
        $("#form1").ajaxSubmit({
             url:url,
             type:'post',
             success:function(data){
              var ret = eval('(' + data + ')');
              alert(ret.msg);
              if(ret.success==true)
              {
                 window.location.href="<s:url value="/jydz"/>/findNewMsrjsdw";
              }
             }		              
        });
		  }else{
			  alert(msg);
		  }
        }
	}

    //加载结算单位名称
     function loadJiesdwData(){
     var url = "<s:url value="/"/>/jydz/loadJiesdwForAuto";          
     $.post(url,function(data){ 
       var projects = eval('(' + data + ')'); 
      $( "#jiesdwmc").autocomplete({            
      	    minLength:2,       	    			
			source:projects,			
           select: function( event, ui ) {
               $("#jiesdwmc").val(ui.item.label);
               $("#jiesdwbm").val(ui.item.jiesdwbm);	
               $("#jiesdwzs").val(ui.item.jiesdwzs);
               $("#faddbr").val(ui.item.faddbr);
               $("#dianh").val(ui.item.dianh);
               $("#chuanz").val(ui.item.chuanz);
               $("#kaihyh").val(ui.item.kaihyh);
               $("#yinhzh").val(ui.item.yinhzh);
               $("#nasrdjh").val(ui.item.nasrdjh);
               $("#youzbm").val(ui.item.youzbm);
               $("#weitdlr").val(ui.item.weitdlr);
               $("#isexist").val("1");
               return false;
			  }
			  
         });
     });
     }
	//校验
	function jiaoyan()
	{
		    $.validator.addMethod("selectNone", 
	        function(value, element)
	        {   
	            if (value == "-1") 
	            {    
	                return false;    
	            }    
	            else    
	            {   
	                return true;    
	            }   
	        },    
	        "必须选择一项" 
	        ); 
	    
	         $("#form1").validate({
			       rules: {
			       "jiesdwmc": "required",
			       "jiesdwzs": "required",
			       "faddbr": "required"	       
			       },
				   messages: {
					   "jiesdwmc":"请输入结算单位名称",
				       "jiesdwzs":"请输入结算单位住所",
				       "faddbr":"请输入法定代表人"
				   }
			   });
	}
	
	</script>
  </head>
  
 <body>
<div id="best1">
<h2><span>新增买受人结算单位</span></h2>
<form name="form1" id="form1">
<input type="hidden" id="isexist" name="isexist" value="0"><!-- 0新增  1已存在 -->
<input type="hidden" name="jiesdwid" value="${newjiesdw[0].jiesdwid}" /> 
<table id="list_search" cellpadding="0" cellspacing="0" border="0">
    <tr>
       <td>
          	所属买受人:<span style="color: red;font-size:16px;vertical-align:middle;">*</span>
          </td>
          <td>
          		<select name="shangjdw" style="width:180px" id="shangjdw">
									<option value="-1" selected>==请选择==</option>
									<c:forEach var="msr" items="${msr}">
										<option value="${msr.value}" <c:if test="${msr.value==newjiesdw[0].shangjdw}"> selected="selected"</c:if>>${msr.label}</option>
									</c:forEach>
				</select>
          </td>
   
       </tr>
    <tr>
      	<td>
          	结算单位名称:<span style="color: red;font-size:16px;vertical-align:middle;">*</span>
          </td>
          <td>
            <input id="jiesdwmc" name="jiesdwmc" type="text" class="longtextbox" title="请录入至少两个汉字关键字选择买受人(如果未找到请先定制买受人)" value="${newjiesdw[0].jiesdwmc}"/>
            <input id="jiesdwbm" name="jiesdwbm" type="hidden">
          </td>
          <td>
          	结算单位住所:<span style="color: red;font-size:16px;vertical-align:middle;">*</span>
          </td>
          <td>
          	<input type="text" name="jiesdwzs" class="longtextbox" value="${newjiesdw[0].jiesdwzs}" /> 
          </td>
          <td>
          	法定代表人:<span style="color: red;font-size:16px;vertical-align:middle;">*</span>
          </td>
          <td>
          	<input type="text" name="faddbr" class="longtextbox" value="${newjiesdw[0].faddbr}" /> 
          </td>
       </tr>
       <tr>
          <td>
          	电话:
          </td>
          <td>
          	<input type="text" name="dianh" class="longtextbox" value="${newjiesdw[0].dianh}" /> 
          </td>
      	<td>
          	传真:
          </td>
          <td>
          	<input type="text" name="chuanz" class="longtextbox" value="${newjiesdw[0].chuanz}" /> 
          </td>
          <td>
          	开户银行:
          </td>
          <td>
          	<input type="text" name="kaihyh" class="longtextbox" value="${newjiesdw[0].kaihyh}" /> 
          </td>
       </tr>
       <tr>
          <td>
          	银行帐号:
          </td>
          <td>
          	<input type="text" name="yinhzh" class="longtextbox" value="${newjiesdw[0].yinhzh}" /> 
          </td>
      	<td>
          	纳税人登记号:
          </td>
          <td>
          	<input type="text" name="nasrdjh" class="longtextbox" value="${newjiesdw[0].nasrdjh}" /> 
          </td>
          <td>
          	邮政编码:
          </td>
          <td>
          	<input type="text" name="youzbm" class="longtextbox" value="${newjiesdw[0].youzbm}" /> 
          </td>
       </tr>
       <tr>
          <td>
          	委托代理人:
          </td>
          <td>
          	<input type="text" name="weitdlr" class="longtextbox" value="${newjiesdw[0].weitdlr}" /> 
          </td>
      	<%-- <td>
          	所属地区:
          </td>
          <td>
          	<input type="text" name="suosdq" class="longtextbox" value="${newjiesdw[0].suosdq}" /> 
          </td>
          <td>
          	行业:
          </td>
          <td>
          	<input type="text" name="hangy" class="longtextbox" value="${newjiesdw[0].hangy}" /> 
          </td> --%>
       </tr>    
        <tr>
		    <td colspan="6" align="center">	
		            <input id="but1" type="button" value="保存" />&nbsp;&nbsp;&nbsp;
			        <input id="but2" type="reset" value="重置" "/>&nbsp;&nbsp;&nbsp;
			        <input id="but3" type="button" name="" value="返回" onclick="javascript:history.back();"/>
		    </td>
        </tr>
  </table> 
</form>
</div> 
<div id="dialog-confirm" title="是否确认保存？"></div>
  </body>
</html>
